Public Class ReportSchedule
    Inherits Base

    Private mlServerID As Long = Base.NODATA
    Private mlDatabaseID As Long = Base.NODATA
    Private miDelayDays As Integer
    Private mbIsActive As Boolean = True
    Private msTimeOfDay As String
    Private msRecipientEmailAddresses As String
    Private msLastReportCompileDate As String
    Private msLastReportSendDate As String

    Public Sub New()
        MyBase.New()

        _New()
    End Sub

    Public Sub New(ByVal lID As Long)
        MyBase.New(lID)
    End Sub

    Friend Sub _New()
        Dim oNextID As New DBNextIDValue("ReportSchedule")
        Dim lNextID As Long = oNextID.NextValue

        Me.ID = lNextID
    End Sub

#Region "Properties"
    Public Property ServerID() As Long
        Get
            Return mlServerID
        End Get
        Set(ByVal value As Long)
            mlServerID = value
        End Set
    End Property

    Public Property DatabaseID() As Long
        Get
            Return mlDatabaseID
        End Get
        Set(ByVal value As Long)
            mlDatabaseID = value
        End Set
    End Property

    Public Property DelayDays() As Integer
        Get
            Return miDelayDays
        End Get
        Set(ByVal value As Integer)
            miDelayDays = value
        End Set
    End Property

    Public Property IsActive() As Boolean
        Get
            Return mbIsActive
        End Get
        Set(ByVal value As Boolean)
            mbIsActive = value
        End Set
    End Property

    Public Property TimeOfDay() As String
        Get
            Return msTimeOfDay
        End Get
        Set(ByVal value As String)
            msTimeOfDay = value
        End Set
    End Property

    Public Property RecipientEmailAddresses() As String
        Get
            Return msRecipientEmailAddresses
        End Get
        Set(ByVal value As String)
            msRecipientEmailAddresses = value
        End Set
    End Property

    Public Property LastReportCompileDate() As String
        Get
            Return msLastReportCompileDate
        End Get
        Set(ByVal value As String)
            msLastReportCompileDate = value
        End Set
    End Property

    Public Property LastReportSendDate() As String
        Get
            Return msLastReportSendDate
        End Get
        Set(ByVal value As String)
            msLastReportSendDate = value
        End Set
    End Property

    Public Sub GetTimeOfDay( _
                    ByRef iHour As Integer, _
                    ByRef iMinute As Integer, _
                    ByRef bIsPM As Boolean)

        Dim i24Hr As Integer = Val(msTimeOfDay.Substring(0, 2))
        If i24Hr < 12 Then
            iHour = i24Hr
            bIsPM = False

        ElseIf i24Hr = 12 Then
            iHour = i24Hr
            bIsPM = True

        Else
            iHour = i24Hr - 12
            bIsPM = True
        End If

        iMinute = Val(msTimeOfDay.Substring(2, 2))
    End Sub

    Public Sub SetTimeOfDay( _
                    ByVal iHour As Integer, _
                    ByVal iMinute As Integer, _
                    ByVal bIsPM As Boolean)

        Dim i24Hr As Integer = iHour

        If bIsPM = True Then
            If i24Hr > 12 Then
                i24Hr = i24Hr + 12
            End If
        End If

        msTimeOfDay = New String("0", 2 - i24Hr.ToString.Length) & i24Hr.ToString & _
              New String("0", 2 - iMinute.ToString.Length) & iMinute.ToString
    End Sub
#End Region

#Region "database"
    Public Sub Load()
        Dim oObject As New DBReportSchedule

        oObject.Load(Me)
    End Sub

    Public Sub Save()
        Dim oObject As New DBReportSchedule

        If mbObjectExists = True Then
            oObject.Update(Me)
        Else
            Me.CreateDate = Now
            oObject.Add(Me)
            mbObjectExists = True
        End If
    End Sub

    Public Sub Delete()
        Dim oObject As New DBReportSchedule

        oObject.Delete(Me)
        mbObjectExists = False
    End Sub
#End Region

End Class
